package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.CallBean
import com.haoshuang.zhouzhoubang.model.bean.GroupBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ManagerMemberViewModel : BaseViewModel() {


    val getTeamMemberListData = StatefulMutableLiveData<ArrayList<GroupBean.AllPeople>>()
    fun getTeamMemberList(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<GroupBean.AllPeople>>("api/Team/team_member_list", *params,
                onStart = {
                    getTeamMemberListData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getTeamMemberListData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getTeamMemberListData.value = StateData.Success(it)
                })
        }
    }

    /**
     * 删除成员
     */
    val delMemberData = StatefulMutableLiveData<Any>()
    fun delMember(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/Team/del_member", *params,
                onStart = {
                    delMemberData.value = StateData.Loading
                },
                onError = { code, msg ->
                    delMemberData.value = StateData.Error(code, msg)
                }, onSuccess = {
//                    delMemberData.value = StateData.Success(it)
                    getTeamMemberList(*params)
                })
        }
    }

}